/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.blog.wordpress.sessionbeans;

import com.blog.wordpress.entities.RegisteredUser;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;
import javax.management.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Breath
 */
@Stateless
public class RegisteredUserFacade extends AbstractFacade<RegisteredUser> implements RegisteredUserFacadeLocal {

    @PersistenceContext(unitName = "com.blog_WordPress_wa")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RegisteredUserFacade() {
        super(RegisteredUser.class);
    }

    @Override
    public List<RegisteredUser> findRegisteredsUsersByUsername(String username) {
        List<RegisteredUser> regiesteredUsers = this.getEntityManager().createNamedQuery("RegisteredUser.findByUsername").getResultList();

        Iterator iter = regiesteredUsers.iterator();
        while (iter.hasNext()) {
            RegisteredUser regUser = (RegisteredUser) iter.next();
            regUser.getUsername();
        }
        return regiesteredUsers;
    }
    
    @Override
    public RegisteredUser findRegUserByUsername(String username){
         return (RegisteredUser) this.getEntityManager().createQuery("SELECT r FROM RegisteredUser r WHERE r.username = :username").setParameter("username", username).getSingleResult();
    }
}
